﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Z.GenerateIconProject.WinForm
{
    public partial class IconLibraryHelper
    {
        public static string GetEnumText(ProjectConfig project)
        {
            var sb = new StringBuilder();

            var dic = new Dictionary<string, string>();

            foreach (IconConfig item in project.IconConfigs)
            {
                sb.Append(GetEnumText(project, item, dic));
            }

            return sb.ToString();
        }

        public static string GetEnumText(ProjectConfig project, IconConfig config, Dictionary<string, string> dict = null)
        {
            string template = "        [Description(\"@(Model.FileName)\")]" + Environment.NewLine + "        @(Model.IconName),";
            var sb = new StringBuilder();

            foreach (FileInfo file in config.SourcePath.ToDirectoryInfo().GetFiles())
            {
                if (dict == null || !dict.ContainsKey(file.Name))
                {
                    string s = template;
                    s = s.Replace("@(Model.FileName)", file.Name);
                    s = s.Replace("@(Model.IconName)", GetIconName(file));

                    sb.AppendLine(s);
                    dict.Add(file.Name, file.Name);
                }
            }
            return sb.ToString();
        }
    }
}